#include <Area_Alpha.h>

#include <World.h>

#include <EnemyShip.h>
#include <Rock.h>
#include <Rock_Static.h>
#include <PlanetA.h>

#include <Camera.h>
#include <PlayerInterface.h>

#include <glut.h>

#include <AreaLoader.h>

#include <LoadGameObject.h>
#include <SetLoadingScreen.h>
#include <ImportAreaData.h>


Alpha::Alpha(World& gameworld)
:Area(gameworld)
{
}

Alpha::~Alpha()
{
}

std::string Alpha::GetName()
{
	return "Alpha";
}

void Alpha::Init()
{
	world.AddCommand( new SetLoadingScreen( &world, 1 ) );
	Global::GameWorldSize = vec2(1000,1000);

	starfields = MakeStarfields(10,100,100);

	//for(unsigned j = 0; j < 10; ++j)
	//for(unsigned i = 0; i < 10; ++i)
	//{
	//	Rock* r = CreateAreaObject( Rock );
	//	r->SetPosition( vec2(50 + i * 5, 50 + j * 5) );
	//	r->SetColor( 0.2f + 0.8f*Global::GetRandomFloat(), 0.2f + 0.8f*Global::GetRandomFloat(), 0.2f + 0.8f*Global::GetRandomFloat() );
	//	if(i == 0 && j == 0)
	//		External::player->SetControlTarget(r);
	//}
	Rock* r = CreateAreaObject( Rock );
	r->SetPosition( vec2(5, 5) );
	External::player->SetControlTarget(r);
	
	for(unsigned j = 0; j < 10; ++j)
	for(unsigned i = 0; i < 10; ++i)
		world.AddCommand( new LoadGameObject<Rock>( this, vec2(50 + i * 5, 50 + j * 5) ) );

	std::list< ColorData > colordata;
	AreaLoader::LoadColorData("./Graphics/test.bmp", colordata);

	ColorKey* key = new ColorKey();
	AddColorType((*key), 255,0,0, Rock);
	AddColorType((*key), 0,0,255, EnemyShip);
	AddColorType((*key), 0,255,0, StaticRock);
	AddColorType((*key), 254,254,0, PlanetA);
	//key.data[ Color::MakeRGB(255,0,0) ] = new ObjectCreatorType<Rock>(this);

	//AreaLoader::ImportDataToArea(this,colordata,key);
	
	world.AddCommand( new ImportAreaData( this, colordata, key ) );
	world.AddCommand( new SetLoadingScreen( &world, 0 ) );
}

void Alpha::UpdateArea()
{
}

void Alpha::Cleanup()
{
}

void Alpha::CustomDraw()
{
	for(unsigned i = 0; i < starfields.size(); ++i)
	{
		if( starfields[i].IsNearby(External::camera->GetPos(), 100) )
		{
			starfields[i].Draw();
		}
	}
}